<template>
	<view class="content b-t">
		<view class="no-address" v-if="addressList.length==0&&hasget">
			无记录
		</view>
		<view class="uni-list">
			<radio-group @change="seldata">
				<label class="list" v-for="(item, index) in addressList" :key="item.id+''">
					<view class="left">
						<view style="padding-right:8rpx">
							<!-- <radio :value="item.id+''" :checked="item.is_default" /> -->
							<radio color="#fa436a" :value="item.id+''"  :checked="item.id==tihuoren.id"/>
						</view>
						<view>
							<view>
								{{item.name}}
							</view>
							<view>
								{{item.phone}}
							</view>
						</view>
					</view>
					<view class="right">
						<text class="yticon" @click.stop="addAddress('edit', item)">编辑</text>
					</view>
				</label>
			</radio-group>
		</view>
		<!-- <view class="list b-b" v-for="(item, index) in addressList" :key="index" @click="checkAddress(item)">
			<view class="wrapper">
				<view class="address-box">
					
					<text class="address">{{item.area}} {{item.detailed_address}}</text>
				</view>
				<view class="u-box">
					<text class="name">{{item.name}}</text>
					<text class="mobile">{{item.phone}}</text>
				</view>
			</view>
			<text class="yticon" @click.stop="addAddress('edit', item)">编辑</text>
		</view> -->
		
		
		<button class="add-btn" @click="addAddress('add')">添加提货人</button>
	</view>
</template>

<script>
	import {  mapState,mapMutations } from 'vuex'
	export default {
		data() {
			return {
				
				hasget:false,
				source: 0,
				addressList: []
			}
		},
		onShow(){
			this.getData()
			
		},
		computed: { //computed中注册
			...mapState([
				
				'tihuoren'
			])
		},
		methods: {
			seldata(ev){
				
				this.settihuoren(this.addressList.filter(item=>{
					return item.id==ev.detail.value
				})[0])
				uni.navigateBack({
					delta: 1
				});
			},
			...mapMutations(['settihuoren']),
			getData(){
				let that=this
				that.apipost('/api/home/picked_up_users').then(res => {
					if(res.Code==10200){
						that.hasget=true
						that.addressList=res.Data
						if(that.addressList.length==1){
							that.settihuoren(that.addressList[0])
						}
					}
					
				}).catch(err=>{
					console.log(err)
				});
			},
			
			addAddress(type, item){
				
				uni.navigateTo({
					url: `/pages/addtihuoren/index?type=${type}&data=${JSON.stringify(item)}`
				})
			},
			//添加或修改成功之后回调
			refreshList(data, type){
				//添加或修改后事件，这里直接在最前面添加了一条数据，实际应用中直接刷新地址列表即可
				this.addressList.unshift(data);
				
				console.log(data, type);
			}
		}
	}
</script>

<style lang='scss'>
	.yticon{
		color:#93969b;
	}
	.no-address{
		color:#909399;
		position:fixed;
		top:48%;
		left:0;
		right:0;
		display:flex;
		align-items: center;
		justify-content: center;
	}
	page{
		padding-bottom: 120rpx;
		box-sizing: border-box;
		overflow: hidden;
		height:100%;
	}
	.content{
		position: relative;
	}
	.list{
		justify-content: space-between;
		display: flex;
		align-items: center;
		padding: 20rpx 30rpx;;
		background: #fff;
		position: relative;
	}
	.list .left{
		display: flex;
		align-items: center;
		
	}
	.wrapper{
		display: flex;
		flex-direction: column;
		flex: 1;
	}
	.address-box{
		display: flex;
		align-items: center;
		.tag{
			font-size: 24rpx;
			color: $base-color;
			margin-right: 10rpx;
			background: #fffafb;
			border: 1px solid #ffb4c7;
			border-radius: 4rpx;
			padding: 4rpx 10rpx;
			line-height: 1;
		}
		.address{
			font-size: 30rpx;
			color: $font-color-dark;
		}
	}
	.u-box{
		font-size: 28rpx;
		color: $font-color-light;
		margin-top: 16rpx;
		.name{
			margin-right: 30rpx;
		}
	}
	.icon-bianji{
		display: flex;
		align-items: center;
		height: 80rpx;
		font-size: 40rpx;
		color: $font-color-light;
		padding-left: 30rpx;
	}
	
	.add-btn{
		position: fixed;
		left: 30rpx;
		right: 30rpx;
		bottom: 16rpx;
		z-index: 95;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 690rpx;
		height: 80rpx;
		font-size: 32rpx;
		color: #fff;
		background-color: $base-color;
		border-radius: 10rpx;
		box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);		
	}
</style>


<style>
</style>
